package cn.iocoder.yudao.module.design.aop;


import cn.iocoder.yudao.module.design.annotation.NodeAction;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 忽略多租户的 Aspect，基于 {@link cn.iocoder.yudao.module.design.annotation.NodeAction} 注解实现，用于一些全局的逻辑。
 *
 * @author 芋道源码
 */
@Aspect
@Component
@Slf4j
public class NodeActionAspect {

    @Around("@annotation(nodeAction)")
    public Object around(ProceedingJoinPoint joinPoint, NodeAction nodeAction) throws Throwable {
        MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature();
        Method method = methodSignature.getMethod();
        NodeAction annotation =  (NodeAction) method.getAnnotation(NodeAction.class);

        Object value1 = AnnotationResolver.newInstance().resolver(joinPoint, annotation.test()); //利用AnnotationResolver进行解析

        //System.out.println("test");
        //todo nodeAction里面应该包含参数，通过参数进行实现个性化功能
        //System.out.println(value1);
        return joinPoint.proceed();
    }

}
